package cn.iocoder.yudao.module.acm.dal.mysql.onboardsupplyplan;

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.acm.controller.admin.onboardsupplyplan.vo.OnboardSupplyPlanPageReqVO;
import cn.iocoder.yudao.module.acm.dal.dataobject.onboardsupplyplan.OnboardSupplyPlanDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalTime;

/**
 * 航机管理-机供品生产计划 Mapper
 *
 * @author yisl
 */
@Mapper
public interface OnboardSupplyPlanMapper extends BaseMapperX<OnboardSupplyPlanDO> {

    default PageResult<OnboardSupplyPlanDO> selectPage(OnboardSupplyPlanPageReqVO reqVO) {

        LambdaQueryWrapperX<OnboardSupplyPlanDO> wrapperX = new LambdaQueryWrapperX<OnboardSupplyPlanDO>()
                .likeIfPresent(OnboardSupplyPlanDO::getPlanCode, reqVO.getPlanCode())
                .likeIfPresent(OnboardSupplyPlanDO::getFlightNo, reqVO.getFlightNo())
                .eqIfPresent(OnboardSupplyPlanDO::getDepTime, reqVO.getDepTime())
                .eqIfPresent(OnboardSupplyPlanDO::getMarkStatus, reqVO.getMarkStatus())
                .orderByDesc(OnboardSupplyPlanDO::getId);
        if (ObjectUtil.isNotEmpty(reqVO.getSearchType())){
            switch (reqVO.getSearchType()){
                case 1:
                    wrapperX.ge(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("00:00"));
                    wrapperX.le(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("06:00"));
                    break;
                case 2:
                    wrapperX.ge(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("06:00"));
                    wrapperX.le(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("12:00"));
                    break;
                case 3:
                    wrapperX.ge(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("12:00"));
                    wrapperX.le(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("18:00"));
                    break;
                case 4:
                    wrapperX.ge(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("18:00"));
                    wrapperX.le(OnboardSupplyPlanDO::getDepTime, LocalTime.parse("23:59:59"));
                    break;
            }
        }
        return selectPage(reqVO, wrapperX);
    }


}